#include "shapewidget.h"
#include <QMouseEvent>
#include <QPainter>
#include <QPixmap>
#include <QBitmap>

ShapeWidget::ShapeWidget(QWidget *parent)
    : QWidget(parent)
{
    QPixmap pix;  //创建一个Qpixmap对象
    pix.load("16.png",0,Qt::AvoidDither|Qt::ThresholdAlphaDither|Qt::ThresholdAlphaDither);
    resize(pix.size());
    setMask(QBitmap(pix.mask()));
}

void ShapeWidget::mousePressEvent(QMouseEvent *event){
    if(event -> button() == Qt::LeftButton){
        dragPosition = event -> globalPos() - frameGeometry().topLeft();
        event -> accept();
    }
    if(event -> button() == Qt::RightButton){
        close();
    }
}

void ShapeWidget::mouseMoveEvent(QMouseEvent *event){
    if(event->buttons() & Qt::LeftButton){
        move(event -> globalPos() - dragPosition);
        event ->accept();
    }
}

void ShapeWidget::paintEvent(QPaintEvent *event){
    QPainter painter(this);
    painter.drawPixmap(0,0,QPixmap("16.png"));
}

ShapeWidget::~ShapeWidget()
{

}
